package awd.bj.jls.webs.api.hystrix;

import awd.bj.base.model.R;
import awd.bj.base.model.Variables;
import awd.bj.jls.webs.api.WorkFlowApi;
import awd.bj.jls.webs.utils.Result;
import awd.bj.jls.webs.utils.ResultUtils;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author WS
 * @Date 2019-09-17 14:21
 */
@Component
public class WorkFlowApiFallBackFactory implements FallbackFactory<WorkFlowApi> {

    Logger logger = LoggerFactory.getLogger(WorkFlowApi.class);

    @Override
    public WorkFlowApi create(Throwable cause) {

        return new WorkFlowApi() {
            @Override
            public R start(String processDefinitionId, String currentUserId, Variables variables) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return R.error("流程执行错误");
            }

            @Override
            public R starts(String processDefinitionId, String currentUserId, String sqr, Variables variables) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return R.error("流程执行错误");
            }

            @Override
            public R execute(String taskId, Variables variables) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return R.error("流程执行错误");
            }

            @Override
            public R deleteAllProcessByRybh(String rybh) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return R.error("流程执行错误");
            }

            @Override
            public R deleteProcessByInstanceId(String processInstanceId, String why) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return R.error("流程执行错误");
            }

            @Override
            public Result findPersonalTaskList(String userId, String roleIds, Variables variables) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return ResultUtils.error("流程执行错误");
            }

            @Override
            public R getTotalOfProcess(String roleIds, Variables variables, String processName) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return R.error("流程执行错误");
            }

            @Override
            public R getProNameByProId(String processDefinitionId) {
                cause.printStackTrace();
                logger.info("进入熔断器=======>>" + Thread.currentThread().getStackTrace()[1].getMethodName() + "方法执行出错");
                return R.error("流程执行错误");
            }
        };
    }
}
